package com.wiz.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.wiz.mapper.PRConfigMapper;
import com.wiz.service.PRConfigService;
import com.wiz.to.AreasTO;
import com.wiz.to.PRConfigTO;
import com.wiz.to.PRTO;
@Service("prconfigService")
public class PRConfigServiceImpl implements PRConfigService {

	@Resource
	private PRConfigMapper prconfigMapper;
	
	@Override
	public List<PRTO> queryAllPR() {
		return prconfigMapper.queryAllPR();
	}
	@Override
	public List<Integer> listPRConfigByHqId(String hqId) {
		List<Integer>ids = new ArrayList<Integer>();
		List<PRConfigTO>prconfs = prconfigMapper.listPRConfigByHqId(hqId);
		for (PRConfigTO prConfigTO : prconfs) {
			ids.add(prConfigTO.getPrId());
		}
		return ids;
	}
	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
	public void modify(String hqId, String prIds)throws Exception {
		List<String>prIdList = Arrays.asList(prIds.split(","));
		List<PRTO>prList =  prconfigMapper.listPR(prIdList);
		
		prconfigMapper.romvePRConfigByHqId(hqId);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("hqId", hqId);
		map.put("list", prList);
		prconfigMapper.addPRConfigs(map);
		
	}

}
